import { TDrugBagRecovery } from "../../../Message/Db/Tables/TDrugBagRecovery";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { PetUtil } from "../view/pet/info/PetUtil";
type int = number;
//class DrugBagRecoveryConfig
    
    export  class DrugBagRecoveryConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (DrugBagRecoveryConfig._instance != null) 
            {
                throw new Error(" DrugBagRecoveryConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TDrugBagRecovery();
                loc1.id = loc2.id;
                loc1.level = loc2.level;
                loc1.recovery = loc2.recovery;
                loc1.recoveryPet = loc2.recoveryPet;
                loc1.type = loc2.type;
                this._map[loc1.type + "_" + loc1.level] = loc1;
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_drug_bag_recovery.json");
            this.write(loc1);
            return;
        }

        public getConfigByLevel(arg1: int, arg2: int, arg3: Boolean=false): int
        {
            var loc1=0;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            if (arg3) 
            {
                loc3 = PetUtil.getRebornTimes(arg2);
                loc2 = int(PetUtil.getLevel(arg2) / 5) * 5;
                loc4 = PetUtil.getFourDigitLevel(loc3, loc2);
                loc1 = (this._map[arg1 + "_" + loc4] as TDrugBagRecovery).recoveryPet;
            }
            else 
            {
                if ((loc2 = int(arg2 / 5) * 5) > 80) 
                {
                    loc2 = 80;
                }
                loc1 = (this._map[arg1 + "_" + loc2] as TDrugBagRecovery).recovery;
            }
            return loc1;
        }

        public static get instance(): DrugBagRecoveryConfig
        {
            if (DrugBagRecoveryConfig._instance == null) 
            {
                DrugBagRecoveryConfig._instance = new DrugBagRecoveryConfig();
            }
            return DrugBagRecoveryConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: DrugBagRecoveryConfig;
    }
